package coffeenc.mall.admin.mapper;

import coffeenc.mall.admin.entity.UmsAdmin;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by coffeenc on 2020/9/15
 */
@Mapper
public interface UmsAdminMapper {
    /**
     * 向数据库中插入一个用户
     * @param umsAdmin 用户信息实体
     */
    @Insert("insert into ums_admin"+
            "(username,password,icon,email,nick_name,note,create_time,login_time,status)"+
            " values"+
            "(#{username},#{password},#{icon},#{email},#{nickname},#{note},#{createTime},#{loginTime},#{status})")
    int insert(UmsAdmin umsAdmin);

    /**
     * 从数据库中选择若干个符合条件的用户，组成列表返回
     */
    @Select("<script>"+
            "select * from ums_admin where 1=1"+
            "<if test='id!=null'> and id=#{id}</if>"+
            "<if test='password!=null'> and password=#{password}</if>"+
            "<if test='username!=null'> and username=#{username}</if>"+
            "<if test='icon!=null'> and icon=#{icon}</if>"+
            "<if test='email!=null'> and email=#{email}</if>"+
            "<if test='nickname!=null'> and nickname=#{nickname}</if>"+
            "<if test='note!=null'> and note=#{note}</if>"+
            "<if test='createTime!=null'> and create_time=#{createTime}</if>"+
            "<if test='loginTime!=null'> and login_time=#{loginTime}</if>"+
            "<if test='status!=null'> and status=#{status}</if>"+
            "</script>")
    @Results(value = {
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "loginTime",column = "login_time")
        }
    )
    List<UmsAdmin> selectByCondition(UmsAdmin umsAdmin);
}
